import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Arrays;      
import java.util.Collection;      
import java.util.Collections;      
import java.util.List;              
public class SetOpt {
	public List intersect(List ls, List ls2) {
		List list = new ArrayList(Arrays.asList(new Object[ls.size()]));
		Collections.copy(list, ls);
		list.retainAll(ls2);
		return list;
	}
	public List union(List ls, List ls2) {
		List list = new ArrayList(Arrays.asList(new Object[ls.size()]));
		Collections.copy(list, ls);
		list.addAll(ls2);
		return list;
	}

	public List diff(List ls, List ls2) {
		List list = new ArrayList(Arrays.asList(new Object[ls.size()]));
		Collections.copy(list, ls);
		list.removeAll(ls2);
		return list;
	}

	public static void main(String[] args) {
		String[] arrayA = new String[] { "a", "b", "c" };
		String[] arrayB = new String[] { "a", "b", "d" };
		List<String> a = Arrays.asList(arrayA);//转换成序列
		List<String> b = Arrays.asList(arrayB);

		SetOpt opt = new SetOpt();
		List l1 = new ArrayList();
		l1.add(1);
		l1.add(2);
		l1.add(3);
		l1.add(4);
		l1.add(4);
		l1.add(9);
		l1.add(4);
		List l2 = new ArrayList();
		l2.add(3);
       l2.add(4);
//		l2.add(5);
//		l2.add(2);
//		l2.add(1);
		List intersectList = opt.intersect(l1, l2);
		System.out.println("交集：");
		for (int i = 0; i < intersectList.size(); i++) {
			System.out.print(intersectList.get(i) + " ");
		}
		System.out.println();
		List unionList = opt.union(l1, l2);
		System.out.println("并集：");
		for (int i = 0; i < unionList.size(); i++) {
			System.out.print(unionList.get(i) + " ");
		}
		System.out.println();
		List diffList = opt.diff(l1, l2);
		System.out.println("差集：");
		for (int i = 0; i < diffList.size(); i++) {
			System.out.print(diffList.get(i) + " ");
		}
		System.out.println();
	}
	
	
}
